package com.yanqu.road.server.cmd.beautyescort;

import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.beautyescort.BeautyEscortProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.beautyescort.CrossBeautyEscortMgr;
import com.yanqu.road.server.manager.beautyescort.CrossEscortPlayerWrap;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_BEAUTY_ESCORT_GET_EVENT_REWARD, desc = "领取事件奖励")
public class CrossBeautyEscortGetEventRewardCmd extends CrossCommand {


    int cartId;
    long dartId;
    long playerId;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        BeautyEscortProto.BeautyEscortGetEventRewardReqMsg reqMsg = BeautyEscortProto.BeautyEscortGetEventRewardReqMsg.parseFrom(packet.getBytes());
        cartId = reqMsg.getCartId();
        dartId = reqMsg.getDartId();
        playerId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossEscortPlayerWrap escortPlayer = CrossBeautyEscortMgr.getEscortPlayer(serverId, playerId);
        if (escortPlayer != null) {
            BeautyEscortProto.BeautyEscortGetEventRewardRespMsg.Builder respMsg = escortPlayer.getEventReward(cartId, dartId);
            if (respMsg.getRet() != 0) {
                ret = respMsg.getRet();
                return;
            }
            MessageHelper.sendPacket(serverId, playerId, YanQuMessageUtils.buildMessage(Protocol.S_BEAUTY_ESCORT_GET_EVENT_REWARD_FROM_CROSS, respMsg));
        }
    }

    @Override
    public void sendData() {
        if(ret != 0){
            BeautyEscortProto.BeautyEscortGetEventRewardRespMsg.Builder respMsg = BeautyEscortProto.BeautyEscortGetEventRewardRespMsg.newBuilder();
            respMsg.setRet(ret);
            MessageHelper.sendPacket(serverId, playerId, YanQuMessageUtils.buildMessage(Protocol.U_BEAUTY_ESCORT_GET_EVENT_REWARD, respMsg));
        }
    }
}
